package com.edu.scnu.element;

import java.awt.Graphics;
import java.awt.Image;

import javax.swing.ImageIcon;

public class MapObj extends ElementObj{

	// 为墙体增加血量
	private int hp;
	private String name; // 墙的type也可以用枚举
	
	@Override
	public void showElement(Graphics g) {
		g.drawImage(this.getIcon().getImage(), 
				this.getX(), this.getY(), 
				this.getW(), this.getH(), null);
	}
	
	@Override // 如果可以传入 墙类型，x，y
	public ElementObj createElement(String str) {
		String[] arr = str.split(",");
		// 先写一个假的图片
		ImageIcon icon2 = null;
		icon2 = new ImageIcon("image/background/" + arr[2] + ".png");
		Image originalImage = icon2.getImage();
        int width = icon2.getIconWidth() * 2;
        int height = icon2.getIconHeight() * 2;
        Image scaleImage = originalImage.getScaledInstance(width, height, Image.SCALE_SMOOTH);
        ImageIcon newIcon = new ImageIcon(scaleImage);
		int x = Integer.parseInt(arr[0]);
		int y = Integer.parseInt(arr[1]);
		int w = newIcon.getIconWidth();
		int h = newIcon.getIconHeight();
		this.setH(h);
		this.setW(w);
		this.setX(x);
		this.setY(y);
		this.setIcon(newIcon);
		return this;
	}
	
	@Override // 说明 这个设置扣血的方法需要自己思考重新思考
	public void setLive(boolean live) {
		// 只是使用被调用一次就减少一次血
		if("IRON".equals(name)) {
			this.hp--;
			if(this.hp > 0) {
				return;
			}
		}
		super.setLive(live);
	}

	private long fileTime = 0L;
	private long timer = 10L;
	
	@Override
	protected void move(long gameTime) {
		if (gameTime >= fileTime + timer) {
			this.setY(this.getY() + 1);
			fileTime = gameTime;
		}
	}
}
